package com.lintf.bot.rabbitmq;

import com.alibaba.fastjson2.JSONObject;
import com.lintf.bot.rabbitmq.constant.Constants;
import com.lintf.bot.wechat.dto.NotificationsSendDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author lintf
 */
@Slf4j
@Component
public class MessageProducer {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    public void sendLikeNotification(NotificationsSendDTO dto) {
        log.info("======生产者开始发送队列消息======");
        rabbitTemplate.convertAndSend(Constants.MY_EXCHANGE, Constants.LIKE_NOTIFICATION_ROUTE_KEY, JSONObject.toJSONString(dto));
        log.info("======队列消息发送完毕======");
    }

    public void sendNotification(NotificationsSendDTO dto) {
        log.info("======生产者开始发送队列消息======");
        rabbitTemplate.convertAndSend(Constants.MY_EXCHANGE, Constants.NOTIFICATION_ROUTE_KEY, JSONObject.toJSONString(dto));
        log.info("======队列消息发送完毕======");
    }

    public void sendItemNotification(NotificationsSendDTO dto) {
        log.info("======生产者开始发送队列消息======");
        rabbitTemplate.convertAndSend(Constants.MY_EXCHANGE, Constants.ITEM_NOTIFICATION_ROUTE_KEY, JSONObject.toJSONString(dto));
        log.info("======队列消息发送完毕======");
    }
}
